﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Proje
{
    class RouteFileConnector
    {
        FileStream file;
        StreamWriter writer;
        StreamReader reader;

        public bool insert(Route route) {
            try
            {
                file = new FileStream(FilePath + "\\" + route.number, FileMode.Append);
                writer = new StreamWriter(file);
                writer.WriteLine(route.date + "|" + route.bus);
                for (int i = 0; i < route.stopPoints.Count; i++)
                {

                    string s = route.stopPoints[i].name + "|" + route.stopPoints[i].time;
                    if (i != route.stopPoints.Count - 1)
                        s = s + "&";
                    writer.Write(s);
                }
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
            finally {
                writer.Close();
                file.Close();
            }
            
        }


        private static string SettingsFolder
        {
            get
            {
                string folder = @"C:\Users\AHMETCAN\Desktop\Sefer";
                if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
                return folder;
            }

        }

 
        string FilePath {
            get {
                return Path.Combine(SettingsFolder, "");

            }
        }
    }
}
